import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'bottom-navitor-bar-item.dart';
import 'icon-text-button.dart';

class BottomNavitorBar extends StatefulWidget {
  int? currentIndex;
  void Function(int index) onPressed;
  List<BottomNavitorBarItem> items;

  BottomNavitorBar(
      {super.key,
      this.currentIndex = 0,
      required this.onPressed,
      required this.items});

  @override
  State<StatefulWidget> createState() {
    return _BottomNavitorBar();
  }
}

class _BottomNavitorBar extends State<BottomNavitorBar> {
  List<Widget> buildItems() {
    return widget.items.asMap().keys.map((index) {
      BottomNavitorBarItem item = widget.items[index];

      return IconTextButton(
        icon: item.icon,
        text: item.label,
        color: widget.currentIndex == index
            ? Colors.green
            : Color.fromARGB(255, 105, 104, 104),
        onPressed: () {
          widget.onPressed(index);
        },
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: buildItems());
  }
}
